# Create your models here.
# 退货 退货原因 发货  退货地址设置
# 汇率设置
# 订单操作
from datetime import datetime
from django.db import models
from users.models import UserInfo
from trades.models import PayInfo, OrderInfo
from django.utils import timezone


class ReturnReason(models.Model):
    """
    退货原因
    """
    name = models.CharField(max_length=100, verbose_name='退货原因')
    sort = models.SmallIntegerField(verbose_name='排序')
    is_display = models.SmallIntegerField('是否显示')
    add_time = models.DateTimeField(verbose_name='添加时间', default=timezone.now)


class OrderTimeLine(models.Model):
    """
    订单历史操作
    标记动态  发货  谁发的快递
    """
    user = models.ForeignKey(UserInfo, verbose_name="用户", on_delete=models.CASCADE)
    pay = models.ForeignKey(PayInfo, verbose_name="订单", on_delete=models.CASCADE)
    add_time = models.DateTimeField(verbose_name='操作时间', default=datetime.now)


class ReturnAddress(models.Model):
    # 退货信息  默认的退货地址
    name = models.CharField(verbose_name='收货人', max_length=20)
    phone = models.CharField(verbose_name='手机', max_length=20)
    address = models.TextField(verbose_name='收货地址')
    code = models.CharField(verbose_name='邮编', max_length=10)


class SystemSet(models.Model):
    """
    系统基本设置
    """
    # 时间
    normalOrderOvertime = models.SmallIntegerField(verbose_name='未付款，订单自动关闭')
    confirmOvertime = models.SmallIntegerField(verbose_name='未收货，订单自动完成')
    finishOvertime = models.SmallIntegerField(verbose_name='自动结束交易，不能申请售后')
    commentOvertime = models.SmallIntegerField(verbose_name='自动五星好评')
    flashOrderOvertime = models.SmallIntegerField(verbose_name='秒杀订单')

    # 汇率
    exchangeRate = models.FloatField(verbose_name='汇率设置')

    # logo
    logo = models.URLField(null=True, blank=True)
    # 公告
    notice = models.TextField(null=True, blank=True)


class ReturnGood(models.Model):
    """
    退货表
    """
    ORDER_STATUS = (
        ('start', '待处理'),
        ('ing', '退回中'),
        ('back', '已完成'),
        ('end', '已拒绝'),
    )
    user = models.ForeignKey(UserInfo, verbose_name="用户", on_delete=models.CASCADE)
    order = models.ForeignKey(OrderInfo, verbose_name="子订单", on_delete=models.CASCADE)
    status = models.CharField(verbose_name='状态', choices=ORDER_STATUS, default='start', max_length=10)
    return_sn = models.CharField(verbose_name='退货编号', default='', null=True, blank=True, unique=True, max_length=50)
    money = models.FloatField(verbose_name='退货金额')
    reason = models.CharField(verbose_name='退货原因', max_length=100)
    desc = models.TextField(verbose_name='描述')
    file = models.FileField(upload_to="return", verbose_name="上传的文件", help_text="上传的文件")
    add_time = models.DateTimeField(verbose_name='操作时间', default=datetime.now)


class RoleList(models.Model):
    name = models.CharField(verbose_name='角色名称', max_length=100)
    desc = models.TextField(verbose_name='描述')
    is_display = models.SmallIntegerField(verbose_name='是否启用')
    add_time = models.DateTimeField(verbose_name='操作时间', default=datetime.now)


class MenuList(models.Model):
    """
    和用户关系一对一
    """
    user = models.ForeignKey(UserInfo, verbose_name="用户", on_delete=models.CASCADE)
    role = models.ForeignKey(RoleList, verbose_name="角色", on_delete=models.CASCADE)
    parentId = models.ForeignKey('self', null=True, blank=True, default=None,
                                 verbose_name='父级分类',
                                 on_delete=models.CASCADE)
    createTime = models.DateTimeField(verbose_name='操作时间', default=datetime.now)
    title = models.CharField(verbose_name='分类名称', max_length=100)
    level = models.CharField(verbose_name='等级', max_length=100)
    sort = models.CharField(verbose_name='排序', max_length=100)
    name = models.CharField(verbose_name='图标名称', max_length=100)
    icon = models.CharField(verbose_name='排序', max_length=100)
    hidden = models.SmallIntegerField(verbose_name='是否隐藏', default=0)


class Notice(models.Model):
    """
    首页的公告 系统全局公告
    """
    title = models.CharField(verbose_name='公告标题', max_length=100)
    content = models.TextField(verbose_name="公告内容")
    is_index = models.BooleanField(verbose_name='首页公告')
    add_time = models.DateTimeField(verbose_name='操作时间', default=datetime.now)


from django.db import models

# Create your models here.
'''
CREATE TABLE `sys_region` (
  `region_id` varchar(10) NOT NULL COMMENT '地区主键编号',
  `region_name` varchar(50) NOT NULL COMMENT '地区名称',
  `region_short_name` varchar(10) DEFAULT NULL COMMENT '地区缩写',
  `region_code` varchar(20) DEFAULT NULL COMMENT '行政地区编号',
  `region_parent_id` varchar(10) DEFAULT NULL COMMENT '地区父id',
  `region_level` int(2) DEFAULT NULL COMMENT '地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县',
  PRIMARY KEY (`region_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='地区表';
'''


class Region(models.Model):
    """
      `region_level` int(2) DEFAULT NULL COMMENT '地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县',

    """
    id = models.AutoField(primary_key=True)
    region_id = models.CharField(max_length=10)
    region_name = models.CharField(max_length=50, null=True)
    region_short_name = models.CharField(max_length=10, null=True)
    region_code = models.CharField(max_length=20)
    region_parent_id = models.CharField(max_length=10)
    region_level = models.SmallIntegerField()
